package me.sealer.jmx.agent;

import lombok.extern.slf4j.Slf4j;
import me.sealer.jmx.mbean.Hello;

import javax.management.*;
import java.lang.management.ManagementFactory;

/**
 * MBean
 * 可用jconsole查看
 * @author sealer
 * @date 2018/01/19.
 */
@Slf4j
public class HelloAgent {
    public static void startAgent() throws Exception {
//        MBeanServer server = MBeanServerFactory.createMBeanServer();
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName helloName = new ObjectName("me.sealer.jmx:type=Hello");
        server.registerMBean(new Hello(), helloName);
        log.debug("waiting forever......");
        Thread.sleep(Long.MAX_VALUE);
    }

    public static void main(String[] args) throws Exception {
        startAgent();
    }
}
